package com.dumian.apple.sqlitetest;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteDatabase.CursorFactory;
import android.database.sqlite.SQLiteOpenHelper;
import android.util.Log;

public class StuDBHelper extends SQLiteOpenHelper {
             private static final String TAG = "TestSQLite";
             public static final int VERSION = 1;

             //必须要有构造函数
            public StuDBHelper(Context context, String name, CursorFactory factory,
                                  int version) {
            super(context, name, factory, version);
         }

             // 当第一次创建数据库的时候，调用该方法
             public void onCreate(SQLiteDatabase db) {
                 String sql = "create table User_table(id int,sname varchar(10),sage int,ssex varchar(10))";
                 String sql1 = "create table UserInfo_table(UserName varchar(10),sign varchar(40),avatar varchar(10),background varchar(10),state varchar(1))";
                 String sql2 = "create table Friends_table(Username varchar(10),FriendName varchar(10))";
                 String sql3 = "create table Groups_table(GroupName varchar(10),creater varchar(10))";
                 String sql4 = "create table GroupInfo_table(GroupName varchar(10),GroupMemberName varchar(10))";
                 //输出创建数据库的日志信息
                 Log.i(TAG, "create Database------------->");
         //execSQL函数用于执行SQL语句
                 db.execSQL(sql);
                 db.execSQL(sql1);
                 db.execSQL(sql2);
                 db.execSQL(sql3);
                 db.execSQL(sql4);


         }

             //当更新数据库的时候执行该方法
             public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
         //输出更新数据库的日志信息
                 db.execSQL("drop if table exists users");
                 onCreate(db);
                 Log.i(TAG, "update Database------------->");
         }
     }